package com.bootdo.common.config;

import javax.servlet.MultipartConfigElement;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Component
class WebConfigurer extends WebMvcConfigurerAdapter {
	@Autowired
	BootdoConfig bootdoConfig;
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/files/**").addResourceLocations("file:///"+bootdoConfig.getUploadPath());
	}

	/**
	 * 文件临时上传路径
	 * @return
	 */
	@Bean
    MultipartConfigElement multipartConfigElement() {  
       MultipartConfigFactory factory = new MultipartConfigFactory();  
       factory.setLocation(bootdoConfig.getUploadPath()+"/temp");
       return factory.createMultipartConfig();  
    }
	
}